package com.tywj.panda.travel

import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.tywj.lib.core.widget.recycleview.adapter.BaseViewHolder
import com.tywj.panda.customer.common.entity.TravelEntity
import com.tywj.panda.customer.common.widget.recyclerview.MyBaseAdapter

/**
 * 行程中的item 手动控制显示或隐藏
 */
//时间显示为一维数组，行程则为二维数组
class TravelSubAdapter : MyBaseAdapter<TravelEntity.DataBean>(R.layout.travel_recycle_item_sub_travel) {

    override fun convert(helper: BaseViewHolder, item: TravelEntity.DataBean) {
        super.convert(helper, item)

        helper.setText(R.id.tvDate, item.lineTravelDate)

        helper.setGone(R.id.flDate, item.lineTravelDate.isNotEmpty())

        handleRecyclerView(helper.getView(R.id.rvList), item.listTravel)
    }


    private fun handleRecyclerView(recycle: RecyclerView, list: ArrayList<TravelEntity.DataBean>) {

        if (recycle.layoutManager == null) {
            recycle.layoutManager = LinearLayoutManager(recycle.context)
        }
        var adapter = recycle.adapter
        if (adapter == null) {
            adapter = TravelAdapter()
            recycle.adapter = adapter
        }
        (adapter as TravelAdapter).setNewData(list)
    }
}